from langchain_community.utilities import SQLDatabase
from langchain_community.tools import QuerySQLDatabaseTool, InfoSQLDatabaseTool
from patagent.llm import PatsnapLLM
import os
from dotenv import load_dotenv
load_dotenv()

host = os.getenv("MYSQL_HOST")
port = os.getenv("MYSQL_PORT")
user = os.getenv("MYSQL_USERNAME")
password = os.getenv("MYSQL_PASSWORD")
database = os.getenv("MYSQL_DATABASE")

llm = PatsnapLLM()
db = SQLDatabase.from_uri(f"mysql+pymysql://{user}:{password}@{host}:{port}/{database}")

execute_info = InfoSQLDatabaseTool(db=db)
execute_query = QuerySQLDatabaseTool(db=db)

# print(execute_query('select dt,table_name,insert_cnt,update_cnt from table_summary where dt >= DATE_SUB(CURDATE(), INTERVAL 14 DAY) ORDER BY dt DESC'))